package com.net.oil.main.adapter;

import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import java.util.List;

import androidx.viewpager.widget.PagerAdapter;

/**
 * 作者：lch
 * 时间：2017/10/25:10:37
 * 邮箱：245850413@qq.com
 * 说明：
 */

public class IntroduceViewPagerAdapter extends PagerAdapter {

    private List<ImageView> imageViews;

    public IntroduceViewPagerAdapter(List<ImageView> imageViews){
        this.imageViews = imageViews;
    }

    @Override
    public int getCount() {
        return imageViews.size();
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == object;
    }

    @Override
    public ImageView instantiateItem(ViewGroup container, int position) {
        ImageView imageView = imageViews.get(position % imageViews.size());
        container.addView(imageView);
        return imageView;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        if (position < imageViews.size()){
            container.removeView(imageViews.get(position % imageViews.size()));
        }
    }
}
